//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this sample source code is subject to the terms of the Microsoft
// license agreement under which you licensed this sample source code. If
// you did not accept the terms of the license agreement, you are not
// authorized to use this sample source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the LICENSE.RTF on your install media or the root of your tools installation.
// THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES OR INDEMNITIES.
//
//
// (C) Copyright 2006 Marvell International Ltd.
// All Rights Reserved
//
//------------------------------------------------------------------------------
//
//  File: loader.h
//
//  This file contains definitions specific to the bootloader.
//
#ifndef _LOADER_H_
#define _LOADER_H_

#include <blcommon.h>
#include <halether.h>
#include <image_cfg.h>
#include <oal_kitl.h>
#include <oal_log.h>
#include "monahans_base_regs.h"
#include "Littleton.h"
#include "image_cfg.h"
#include <ebootcfg.h>
#include <fmd.h>

/* *Refer to config.bib and eboot.bib for memory layout* */
     
//------------------------------------------------------------------------------
// Defines
//
// temp



#define BL_SDMMC_DOWNLOAD 2

#define EBOOT_VERSION_MAJOR             1
#define EBOOT_VERSION_MINOR             7


#ifdef OSV_WINCENET
#define OS_RAM_IMAGE_START				( SDRAM_BASE_UA + IMAGE_BOOT_DOWNLOADCACHE_RAM_OFFSET)
#define OS_RAM_IMAGE_SIZE_NUM_BLOCKS	(0x03B00000 / 0x4000)
#define LB_OS_RAM_IMAGE_SIZE_NUM_BLOCKS	(0x03B00000 / 0x00020000)
#else
// Loads the IPL.
#define OS_RAM_IMAGE_START       		(IMAGE_IPL_RAM_UA_START) //if 64M DDR, it's 0x83900000. This is the virtual address.
#define OS_RAM_IMAGE_SIZE_NUM_BLOCKS	(IMAGE_IPL_RAM_SIZE / 0x4000) //0x00020000 / 0x4000  
#define LB_OS_RAM_IMAGE_SIZE_NUM_BLOCKS	(IMAGE_IPL_RAM_SIZE / 0x00020000) //0x00020000 / 0x4000
#endif

#define DOWNLOAD_RAM_BUFFER_START	(0x80001000) // Virtial Start of RAM after EBOOT args.

// End of RAM                           
#ifdef BSP_DDR128MB
 #define OS_RAM_END                      (0x88000000) // 128MB
#else
 #define OS_RAM_END                      (0x84000000) // 64MB
#endif

typedef DWORD  BLOCK_ID;

//------------------------------------------------------------------------------
// External functions
//
extern void InitDebugSerial(UINT32 DbgSerPhysAddr, BOOL fUsePhysical);
extern void SpinForever(void);
extern void Reboot(void);
extern DWORD OEMEthGetSecs(void);

BOOL SDMMCReadData(DWORD cbData, LPBYTE pbData, DWORD offset);

extern UINT32 InitSpecifiedEthDevice(OAL_KITL_ARGS *pKITLArgs, UINT32 EthDevice);
extern void EthernetSetMACAddress(BYTE *arg);

extern void Launch(unsigned int uAddr);

//flash fucntion for main.c
extern BOOL FlashInit(UINT32 FlashStart, UINT32 FlashLength);


extern BOOL FlashReadNAND(UINT32 startBlock, UINT8 *pDataBuffer, UINT32 size);
extern BOOL FlashWriteNAND(UINT32 startBlock, UINT8 *pDataBuffer, UINT32 size);

//flash function for menutest.c
extern BOOL CreateRelocTable(BLOCK_ID block, BLOCK_ID lastProtectBlock, BOOL fEmpty);
extern BOOL ReadRelocTable(BLOCK_ID block);
extern void dumpData( unsigned char * data, 	WORD num_bytes, WORD offset );
extern void DumpBootLoaderImage(void);
extern BOOL FlashReadSector(SECTOR_ADDR sector, UINT8 *pTmp, SectorInfo *pSectorInfo);
extern BOOL FlashWriteSector(SECTOR_ADDR sector, VOID *pBuffer, SectorInfo *pInfo);
extern BOOL FlashEraseBlock(BLOCK_ID block);
extern BOOL FlashReadNANDFlash(UINT32 startBlock, UINT32 endBlock);
extern BOOL FlashFormatNANDFlash(UINT32 startBlock, UINT32 endBlock);
extern BOOL LoadImageFromFlash(BLOCK_ID imageStartBlock, UINT8 *pImageBufferRam, UINT16 numBlocks);
extern BOOL ReservedSpareArea(BLOCK_ID start, int NoOfBlocks);

extern void UpdateImageAddr(BLOCK_ID imageStartBlock, UINT16 numBlock);


//------------------------------------------------------------------------------
// Structure definitions. 
//
// The EBOOT_CFG structure holds a variety of configuration parameters.
// When adding new parameters, make sure that the size of the structure in bytes is 
// an integral number of DWORDS.  Pad the structure if necessary.

typedef struct
{
    DWORD dwBaseAddr;
    DWORD dwOffsetAddr;
    UINT8 *pbData;
    DWORD cbData;
    DWORD dwStartBlock;
    DWORD dwNumBlocksWritten;
} EBOOT_CONTEXT, *PEBOOT_CONTEXT;

//------------------------------------------------------------------------------
// Enumerated type definitions. 
//
typedef enum
{
    ETH_DEVICE_PCMCIA0 = 0,
    ETH_DEVICE_PCMCIA1,
    ETH_DEVICE_SMSC,
    ETH_DEVICE_RNDIS
} ETH_DEVICE_TYPE;

typedef enum
{
    IMAGE_TYPE_RAMIMAGE,
    IMAGE_TYPE_FLASHIMAGE,
    IMAGE_TYPE_BOOTLOADER,
    IMAGE_TYPE_IPL,
    IMAGE_TYPE_DEBUGNK,
    IMAGE_TYPE_UNKNOWN
} IMAGE_TYPE, *PIMAGE_TYPE;
//------------------------------------------------------------------------------


typedef enum
{
    NON_TRUSTED_MODE_A0,
    TRUSTED_MODE_A1
} PLATFORM_MODE_T;

typedef enum
{
	BLOCK_SIZE_16KB = 16,
	BLOCK_SIZE_32KB = 32,
	BLOCK_SIZE_64KB = 64,
	BLOCK_SIZE_128KB= 128 
} NAND_FLASH_BLOCK_SIZE_T;


#endif  // _LOADER_H_.

